package com.itheima.jobs;

import com.itheima.constant.RedisConstant;
import com.itheima.utils.QiniuUtils;
import org.springframework.beans.factory.annotation.Autowired;
import redis.clients.jedis.JedisPool;

import java.util.Set;

public class ClearImgJob {
    @Autowired
    JedisPool jedisPool;

    public void clearImg() {
        //根据在com.itheima.constant.RedisConstant里面两个集合
        Set<String> set = jedisPool.getResource().sdiff(RedisConstant.SETMEAL_PIC_RESOURCES, RedisConstant.SETMEAL_PIC_RESOURCES);
        if (set!=null){
            for (String s : set) {
                //删除七牛云上的图片
                QiniuUtils.deleteFileFromQiniu(s);
                //从Redis集合中删除图片
                jedisPool.getResource().srem(RedisConstant.SETMEAL_PIC_DB_RESOURCES,s);
                System.out.println("清除垃圾图片机制巡行中,准备删除"+s+"图片");
            }
        }
    }
}
